<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 求和
    const addAll = (...args) => {
      console.log('进行了一次计算')
      return args.reduce((prev, cur) => prev + cur, 0)
    }

    // 闭包实现
    const proxyAddAll = (function () {
      let resultGroup = {}
      return function (...args) {
        console.log('args', args)
        const paramStr = args.join(',')
        console.log('paramStr', paramStr)
        console.log('resultGroup', resultGroup, resultGroup.paramStr)
        if (paramStr in resultGroup) {
          return resultGroup[paramStr]
        }
        return resultGroup[paramStr] = addAll(...args)
      }
    })()

    proxyAddAll(1, 2, 3)
    proxyAddAll(1, 2, 3)
  </script>
</body>

</html>